package app.mvp;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import app.mvp.base.mvp.BaseModel;
import app.mvp.utils.CookieUtil;

/**
 * Created by 刘智强 on 2017/4/6.
 */

public class MainModel implements BaseModel<MainModel> {
    private Context context;
    private int id;
    private String name;
    private int age;

    public MainModel() {
    }

    public MainModel(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "MainModel{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    public MainModel setData() {
        MainModel mainModel = new MainModel(1, "zhangsan", 25);
        Log.e("TAG", "setData");
        return mainModel;
    }

    public MainModel setUser() {
        MainModel mainModel = new MainModel(2, "李四", 30);
        Toast.makeText(context, mainModel.getName(), Toast.LENGTH_SHORT).show();
        return mainModel;
    }


    @Override
    public MainModel getDataFromCache(Context context) {


        return new CookieUtil(context).getObject("key", MainModel.class);
    }

    @Override
    public MainModel getDataFromNet(Context context) {
        MainModel mainModel = new MainModel(2, "李四", 30);
        new CookieUtil(context).putObject("key", mainModel);
        return null;
    }

    @Override
    public void setContext(Context context) {
        if (context != null) {
            this.context = context;
        }

    }


}
